# Copyright (C) 2009,2010,2011,2012  Marco Restelli
#
# This file is part of:
#   LDGH -- Local Hybridizable Discontinuous Galerkin toolkit
#
# LDGH is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# LDGH is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LDGH. If not, see <http://www.gnu.org/licenses/>.
#
# author: Marco Restelli                   <marco.restelli@gmail.com>


# List of the object files of the present folder
OBJ= mod_time_integrators_base.o \
     mod_rk.o \
     mod_multistep.o \
     mod_time_integrators.o
OBJ_ODETEST= ode_test.o \
     $(OBJ)

# General settings -----------------------------------

PWD:=$(shell pwd)
BUILDDIR:=$(LDGH_BUILDDIR)/time-integrators

LIBS:=-lshared $(LIBS)
LDFLAGS:=$(LDFLAGS) -L$(LDGH_LIBDIR)

# VPATH includes:
#   PWD for the source files (included by default)
#   BUILDDIR for the .o prerequisites
#   LIBDIR for the libshared.a library
#   BINDIR for the final executable
VPATH:=$(BUILDDIR) $(LDGH_LIBDIR) $(LDGH_BINDIR)

# clear unfinished targets
.DELETE_ON_ERROR:
# define the phony targets
.PHONY: clean

# Main targets ---------------------------------------

libode.a: $(OBJ)
	-rm $(LDGH_LIBDIR)/libode.a
	cd $(BUILDDIR) && $(AR) -r $(LDGH_LIBDIR)/libode.a $(OBJ)
	cp $(BUILDDIR)/*.mod $(LDGH_LIBDIR)/

ode-test: $(OBJ_ODETEST)
	cd $(BUILDDIR) && \
	  $(LD) $(LDFLAGS) $(OBJ_ODETEST) $(LIBS) -o $(LDGH_BINDIR)/ode-test

# General rule: all the .o depend on the libshared library
%.o: %.f90 libshared.a
	cd $(BUILDDIR) && \
	  $(FC) $(FFLAGS) $(MODFLAG)$(LDGH_LIBDIR) -c $(PWD)/$<

clean:
	-rm $(BUILDDIR)/*.o $(BUILDDIR)/*.ilo $(BUILDDIR)/*.mod \
	  $(LDGH_LIBDIR)/libode.a $(LDGH_LIBDIR)/*.mod                 \
	  $(LDGH_BINDIR)/ode-test

# Specific dependencies: because of USE directives ---
# Notice: here we list only the prerequisites which are not already
# included in the libshared.a library, which is a prerequisite of all
# the .o files listed in this Makefile

ode_test.o: \
   mod_time_integrators.o

mod_time_integrators.o: \
   mod_time_integrators_base.o \
   mod_rk.o \
   mod_multistep.o

mod_rk.o: \
   mod_time_integrators_base.o

mod_multistep.o: \
   mod_time_integrators_base.o
